package com.meihua.shellapp.activity.wallet;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.bean.WalletBean;
import com.meihua.shellapp.databean.WalletDataBean;
import com.meihua.shellapp.utils.ToastUtils;
import com.meihua.shellapp.utils.URL;

import butterknife.Bind;
import butterknife.OnClick;

import static com.meihua.shellapp.R.id.rl_bankcard;
import static com.meihua.shellapp.R.id.rl_withdrawals;

/**
 * 作者：lc on 2017/9/26.
 * 邮箱：lc0607live@163.com
 */

public class MyWalletActivity extends BaseActivity {

    @Bind(R.id.iv_top_left)
    ImageView iv_top_left;//返回
    @Bind(R.id.tv_title)
    TextView tv_title;//标题
    @Bind(R.id.tv_account_security)
    TextView tv_account_security;//累计收入
    @Bind(R.id.tv_integral)
    TextView tv_integral;//积分
    @Bind(R.id.tv_money)
    TextView tv_money;//余额

    private WalletDataBean mData;

    @Override
    public int getLayoutId() {
        return R.layout.activity_mywallet;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        iv_top_left.setVisibility(View.VISIBLE);
        iv_top_left.setOnClickListener(this);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("我的钱包");
    }

    @Override
    public void createLoadData() {
        super.createLoadData();
        OkGo.<String>post(URL.getUrl().GETWALLET)
                .params("m_number", MyApplication.getInstance().getUserId())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        WalletBean bean = MyApplication.getInstance().getBeanForJson(WalletBean.class, response.body());
                        if (bean == null) {
                            return;
                        }
                        if (bean.getCode() == 1) {
                            mData = bean.getData();
                            bindData();
                        } else {
                            ToastUtils.getInstance().showToast(bean.getMsg());
                        }
                    }
                });
    }

    private void bindData() {
        tv_money.setText(mData.getCash_income() + "");
        tv_account_security.setText("￥" + mData.getTotal_income() + "元");
        tv_integral.setText(mData.getIntegral() + "个");

    }

    @OnClick({R.id.iv_top_left, R.id.rl_accumulate_dincome, R.id.rl_integral, R.id.rl_bankcard, R.id.rl_withdrawals})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_top_left:
                finish();
                break;
            case R.id.rl_accumulate_dincome:
                 /*累计收入*/
                startActivity(new Intent(this, DincomeActivity.class));
                break;
            case R.id.rl_integral:
                /*我的积分*/
                startActivity(new Intent(this, IntegralActivity.class));
                break;
            case rl_bankcard:
                /*银行卡*/
                startActivity(new Intent(this, BankcardActivity.class));
                break;
            case rl_withdrawals:
                /*提现*/
                startActivity(new Intent(this, WithdrawalsActivity.class));
                break;
        }
    }
}
